package com.itheima.controller;

import com.itheima.pojo.Feedback;
import com.itheima.service.FeedbackService;
import com.itheima.service.FeedbackService;
import com.itheima.utils.MessageConstant;
import com.itheima.utils.ResultUtil;
import com.itheima.vo.FeedbackVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/feedback")
@CrossOrigin
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    /**
     * 批量删除反馈
     *@param feedBackVOList
     * @return java.lang.String
     *@author itheima
     */
    @PostMapping("/deleteBatch")
    public String deleteBatch(@RequestBody List<FeedbackVO> feedBackVOList) {
        try {
            feedbackService.deleteBatch(feedBackVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.result(HttpServletResponse.SC_UNAUTHORIZED,MessageConstant.FEEDBACK_DELETE_FALL);
        }
        return ResultUtil.result(HttpServletResponse.SC_OK,MessageConstant.FEEDBACK_DELETE_SUCCESS);
    }

    /**
     * 编辑反馈
     *@param feedBackVO
     * @return java.lang.String
     *@author itheima
     */
    @PostMapping("/edit")
    public String edit(@RequestBody FeedbackVO feedBackVO) {
        try {
            feedbackService.edit(feedBackVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.result(HttpServletResponse.SC_UNAUTHORIZED,MessageConstant.FEEDBACK_EDIT_FALL);
        }
        return ResultUtil.result(HttpServletResponse.SC_OK, MessageConstant.FEEDBACK_EDIT_SUCCESS);
    }

    /**
     * 获取反馈列表
     *@param feedBackVO
     * @return java.lang.String
     *@author itheima
     */
    @PostMapping("/getList")
    public String getList(@RequestBody FeedbackVO feedBackVO) {
        List<Feedback> feedBackList = null;
        try {
            feedBackList = feedbackService.getList(feedBackVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.result(HttpServletResponse.SC_UNAUTHORIZED,MessageConstant.FEEDBACK_FINDALL_FAIL);
        }
        return ResultUtil.result(HttpServletResponse.SC_OK,feedBackList);
    }

}
